package com.galgram.project.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.galgram.project.entity.*;
import com.galgram.project.mapper.*;
import com.galgram.system.mapper.SysConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.galgram.project.domain.FxCourseDetail;
import com.galgram.project.service.IFxCourseDetailService;

/**
 * 课程详情Service业务层处理
 *
 * @author galgram
 * @date 2024-11-20
 */
@Service
public class FxCourseDetailServiceImpl extends ServiceImpl<FxCourseDetailMapper, FxCourseDetail> implements IFxCourseDetailService {

    @Autowired
    private FxCourseDetailMapper courseDetailMapper;
    @Autowired
    private courseCurriculumMapper curriculumMapper;
    @Autowired
    private FxCourseChapterMapper chapterMapper;
    @Autowired
    private FxCourseSectionMapper sectionMapper;
    @Autowired
    private FxTeacherMapper teacherMapper;

    @Override
    public List<FxCourseDetail> selectFxCourseDetailList(FxCourseDetail fxCourseDetail) {
        return baseMapper.selectFxCourseDetailList(fxCourseDetail);
    }

    @Override
    public CourseDetail selectDetailByCourseId(Long courseId) {
        // 查询课程详情
        CourseDetail courseDetail = courseDetailMapper.selectDetailByCourseId(courseId);
        // 查询资源
        List<Curriculum> curriculumList = curriculumMapper.selectCurriculumList(courseDetail.getId());
        // 遍历资源
        for (int i = 0; i < curriculumList.size(); i++) {
            // 查询章节
            List<Chapter> chapterList = chapterMapper.selectChapterList(curriculumList.get(i).getId());
            // 遍历章节
            for (int j = 0; j < chapterList.size(); j++) {
                // 查询小节
                List<Section> sectionList = sectionMapper.selectSectionList(chapterList.get(j).getId());
                chapterList.get(j).setSection(sectionList);
            }
            curriculumList.get(i).setChapter(chapterList);
        }
        List<Teacher> teachers = teacherMapper.selectTeacherListByDetailId(courseDetail.getId());
        courseDetail.setTeacher(teachers);
        courseDetail.setCurriculum(curriculumList);
        return courseDetail;
    }

}
